package com.qch.edu.lagou.algorithm.divide;

/**
 * @Author qch
 * @Date 2021/7/23
 * 分治思想
 * 计算n次幂(O(log^n))
 */
public class Pow {
    public static int pow(int x,int n)
    {
      /*  if(n==0)
        {
            return 1;
        }*/
        if(n==1)
        {
            return x;
        }
        int half=pow(x,n/2);
        if(n%2==0)
        {
            return half*half;
        }
        else {
            return half*half*x;
        }
    }

    public static void main(String[] args) {
        System.out.println(pow(2,10));
    }
}
